package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.service.MallMemberEquityService;
import com.sc.nft.service.MallMemberEquityTemplateService;
import com.sc.nft.service.MallMemberService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.admin.controller
 * @Project：sc_metago
 * @name：MallMemberController
 * @Date：2024/4/2 11:43
 * @Filename：MallMemberController
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/mall/member")
@Api(tags ="商城会员控制器")
public class MallMemberController {

    private final MallMemberService mallMemberService;
    private final MallMemberEquityTemplateService mallMemberEquityTemplateService;
    private final MallMemberEquityService mallMemberEquityService;

    @ApiOperation(value = "商城会员列表", notes = "商城会员列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
        public PageResult<AdminMallMemberPageDTO> getMallMemberPageDTO(@RequestBody PageRequest pageRequest) {
        return PageResult.success(mallMemberService.getAdminMallMemberPageDTO(pageRequest.getPageNo(),pageRequest.getPageSize()));
    }

    @ApiOperation(value = "添加或者编辑商城会员", notes = "商城会员列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result editMallMember(@Valid  @RequestBody EditAdminMallMemberVO editAdminMallMemberVO) {
        mallMemberService.editMallMember(editAdminMallMemberVO);
        return Result.success();
    }

    @ApiOperation(value = "商城会员详情", notes = "商城会员列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result getAdminMallMemberDetailDTO(@Valid  @RequestBody IdRequest idRequest) {
        AdminMallMemberDetailDTO adminMallMemberDetailDTO = mallMemberService.getAdminMallMemberDetailDTO(idRequest.getId());
        return Result.success(adminMallMemberDetailDTO);
    }

    @ApiOperation(value = "商城会员启用", notes = "商城会员启用", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result enable(@Valid @RequestBody IdRequest idRequest) {
        mallMemberService.enable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "商城会员禁用", notes = "商城会员禁用", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result disable(@Valid @RequestBody IdRequest idRequest) {
        mallMemberService.disable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "商城会员排序", notes = "商城会员排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@RequestBody EditAdminMallMemberSortVO vo) {
        mallMemberService.updateSort(vo.getId(),vo.getSort());
        return Result.success();
    }

    @ApiOperation(value = "商城会员权益模版列表", notes = "商城会员权益模版列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/template/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<MallMemberEquityTemplatePageDTO> geMallMemberEquityTemplatePageDTO(@RequestBody MallMemberEquityTemplatePageVO mallMemberEquityTemplatePageVO) {
        return  PageResult.success(mallMemberEquityTemplateService.getAdminMemberEquityTemplatePageDTO(mallMemberEquityTemplatePageVO));
    }

    @ApiOperation(value = "添加或者编辑商城会员权益模版", notes = "添加或者编辑商城会员权益模版", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/template/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
        public Result editMallMemberEquityTemplate(@Valid  @RequestBody EditMemberEquityTemplateVO editMemberEquityTemplateVO) {
        mallMemberEquityTemplateService.edit(editMemberEquityTemplateVO);
        return Result.success();
    }

    @ApiOperation(value = "商城会员权益模版启用", notes = "商城会员权益模版启用", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/template/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result templatEnable(@Valid @RequestBody IdRequest idRequest) {
        mallMemberEquityTemplateService.enable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "商城会员权益模版禁用", notes = "商城会员权益模版禁用", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/template/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result templateDisable(@Valid @RequestBody IdRequest idRequest) {
        mallMemberEquityTemplateService.disable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "商城会员权益模版详情", notes = "商城会员权益模版详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/template/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result getAdminMallMemberTemplateDetailDTO(@Valid  @RequestBody IdRequest idRequest) {
        MallMemberEquityTemplateDetailDTO adminMallMemberTemplateDetailDTO = mallMemberEquityTemplateService.getAdminMallMemberTemplateDetailDTO(idRequest.getId());
        return Result.success(adminMallMemberTemplateDetailDTO);
    }

    @ApiOperation(value = "商城会员优惠券列表", notes = "商城会员优惠券列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/coupons", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminMallMemberCouponsDTO>> getAdminMallMemberCouponsDTO(@Valid @RequestBody MemberMallActivityCouponsListVO memberMallActivityCouponsListVO) {
        return PageResult.success(mallMemberEquityService.getAdminMallMemberCouponsDTO(memberMallActivityCouponsListVO.getMemberId(),memberMallActivityCouponsListVO.getMemberEquityTemplateId()));
    }

    @ApiOperation(value = "商城会员商品列表", notes = "商城会员优惠券列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/product", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminMallMemberProductDTO>> getAdminMallMemberProductDTO(@Valid @RequestBody MemberMallActivityCouponsListVO memberMallActivityCouponsListVO) {
        return PageResult.success(mallMemberEquityService.getAdminMallMemberProductDTO(memberMallActivityCouponsListVO.getMemberId(),memberMallActivityCouponsListVO.getMemberEquityTemplateId()));
    }

    @ApiOperation(value = "获取可添加至会员权益模版商品列表", notes = "获取可添加至会员权益模版商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/equity/canAdd/product", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminMallMemberProductDTO> getCanAddAdminMallMemberProductDTO(@RequestBody CanAddAdminMallMemberProductVO canAddAdminMallMemberProductVO) {
        return PageResult.success(mallMemberEquityService.getCanAddAdminMallMemberProductDTO(canAddAdminMallMemberProductVO));
    }
}
